package com.gzw.shop.adapter;

import android.content.Context;
import android.net.Uri;

import com.facebook.drawee.view.SimpleDraweeView;
import com.gzw.shop.R;
import com.gzw.shop.bean.ShoppingCart;

import java.util.List;

/**
 * Created by JACKYGUO on 2017-05-08.
 */

public class WearOrderAdapter extends SimpleAdapter<ShoppingCart> {

    private List<ShoppingCart> datas;

    public WearOrderAdapter(Context context, List<ShoppingCart> datas) {
        super(context, datas, R.layout.template_order_wares);
        this.datas = datas;
    }

    @Override
    public void bindData(BaseViewHolder viewHoder, final ShoppingCart item) {

//        viewHoder.getTextView(R.id.text_title).setText(item.getName());
//        viewHoder.getTextView(R.id.text_price).setText("￥"+item.getPrice());
        SimpleDraweeView draweeView = (SimpleDraweeView) viewHoder.getView(R.id.drawee_view);
        draweeView.setImageURI(Uri.parse(item.getImgUrl()));

    }


    public float getTotalPrice() {

        float sum = 0;
        if (!isNull())
            return sum;

        for (ShoppingCart cart :
                datas) {

            sum += cart.getCount() * cart.getPrice();
        }

        return sum;

    }


    private boolean isNull() {

        return (datas != null && datas.size() > 0);
    }
}
